package aimozg.utils;

/**
 * Created by IntelliJ IDEA.
 * User: aimozg
 * Date: 16.07.11
 * Time: 16:47
 */
public class Pair<A,B> implements Cloneable{
	public final A a;
	public final B b;

	public Pair(A a, B b) {
		this.a = a;
		this.b = b;
	}

	public Pair(Pair<A,B> other){
		this(other.a,other.b);
	}

	@SuppressWarnings({"CloneDoesntCallSuperClone"})
	@Override
	protected Pair<A,B> clone() throws CloneNotSupportedException {
		return new Pair<A,B>(this);
	}

	@Override
	public int hashCode() {
		return ((a==null)?0:a.hashCode())<<37 + ((b==null)?0:b.hashCode());
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || !obj.getClass().equals(Pair.class)) return false;
		Pair pobj = (Pair)obj;
		if ((pobj.a == null) ^ (a==null)) return false;
		if ((pobj.b == null) ^ (b==null)) return false;
		if (pobj.a != null && !pobj.a.equals(a)) return false;
		if (pobj.b != null && !pobj.b.equals(b)) return false;
		return true;
	}

	@Override
	public String toString() {
		return "<"+String.valueOf(a)+", "+String.valueOf(b)+">";
	}
}
